/*
	This file is part of Posixcpp library.

	Posixcpp library is free software: you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public License
	as published by the Free Software Foundation, either version 3 of
	the License, or (at your option) any later version.

	Posixcpp library is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU LesserGeneral Public
	License along with Posixcpp library. If not, see
	<http://www.gnu.org/licenses/>.
 */

#ifndef POSIX_ACTIVEOBJECT_HPP
#define	POSIX_ACTIVEOBJECT_HPP

#include "posixcpp.hpp"

namespace posixcpp {

/**
 * @class ActiveObject
 * @brief Abstract active object, wich can starts it's child method or any other function
 */
class ActiveObject {
public:
union ExecutionsRes_t {
    public:
        ExecutionsRes_t(void *ptr) : pointer(ptr) {
            
        }
        ExecutionsRes_t(int num) : number(num) {
            
        }
        void *pointer;
        int number;
    };
    
    virtual ~ActiveObject() {
        
    }
    virtual void start() = 0;
    virtual ExecutionsRes_t waitFinish() = 0;
protected:
    ActiveObject( ExecutionsRes_t res ) :
    m_result(res) {
        
    }
    /**
     * @brief start() will execute this, if other options not set
     */
    virtual void run();
    
    /**
     * @property result
     * @brief the result of thread execution, wich can be achieved after join() call
     */
    
    ExecutionsRes_t result() const {
        return m_result;
    }
    void setResult(ExecutionsRes_t newVal) {
        m_result = newVal;
    }
private:
    /**
     * Execution result
     */
    ExecutionsRes_t m_result;
};

}

#endif	/* POSIX_ACTIVEOBJECT_HPP */
